<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="columns => this.columns = columns"
      :isExportExcel2="true"
      :exportFileName="'经销商账户台账.xlsx'"
    >
    </FilterTable>
    <BaseDialog
      :visible.sync="issearch"
      :title="'经销商查询'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <ownerSeacher  @close="dealercloseHandler" />
    </BaseDialog>
    <BaseDialog
      :visible.sync="issearchKP"
      :title="'开票信息'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <invoice-information :rowData="formData"  @close="KPcloseHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import {getComPaymentt,getuser} from '@/api/partsmanage/financialManagement/findComPayment/index';
import ownerSeacher from '@/pages/partsmanage/claim/approve/ownerSeacher';
import invoiceInformation from './invoiceInformation';
// 油电属性
export const type1=[
  {text: '油车件', value: '1980'},
  {text: '电车件', value: '2000'},
]
// 油电属性
export const type2=[
  {text: '电车件', value: '1012'}
]
export default {
  name: "findComPayment",
  mixins: [dictionary],
  components: {ownerSeacher,invoiceInformation},
  data() {
    return{
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchApi: getComPaymentt,
      formData: null,
      fetchParams: {xhrAbort: true},
      issearchKP:false,
      issearch: false,
      attributes:'beijing'
    };
  },
  created() {
    this.getuser()
  },
  methods: {
    getuser(){
      // 获取当前登录人信息
      getuser({}).then(response=>{
        console.info(response)
        if (response.data.appId=='beijing'){
          this.topFilterList.find(res=>res.fieldName=='bukrs').itemList=type1
        }else{
          this.topFilterList.find(res=>res.fieldName=='bukrs').itemList =type2
        }
      })
    },
    createTopFilterList() {
      return[
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'xskhdm',
          placeholder: '请选择',
          initialValue: '',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          }
        },
        {
          type: 'SELECT',
          label: '油电属性',
          fieldName: 'bukrs',
          placeholder: '请选择...',
          itemList: []
        },
        {
          type: 'RANGE_DATE',
          label: '来款日期',
          fieldName: 'xspzrq1|xspzrq2',
          valueFormat: 'yyyy-MM-dd',
          placeholder: '请选择'
        }
      ]
    },
    createTableColumns () {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '来款流水号',
          dataIndex: 'id',
          sorter: true,
        },
        {
          title: '经销商代码',
          dataIndex: 'xskhdm',
          sorter: true,
        },
        {
          title: '经销商名称',
          dataIndex: 'xskhmc',
          sorter: true,
        },
        {
          title: '油电属性',
          dataIndex: 'bukrs',
          sorter: true,
          render: props => {
            if (props.row.bukrs=='1980'){
              return '油车件'
            } else{
              return '电车件'
            }
          }
        },
        {
          title: '来款日期',
          dataIndex: 'xslkrq',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
        },
        {
          title: '来款金额',
          dataIndex: 'xslkje',
          sorter: true,
          precision: 2,
          render: props => {
            if (props.row.xslsfx=='S'){
              return -(props.row.xslkje)
            } else{
              return props.row.xslkje
            }
          }
        },
        {
          title: 'ERP票号',
          dataIndex: 'xspjfp',
          sorter: true,
          render: props => {
            return <a style="color: blue;text-decoration:underline;" href="#" onClick={() => this.clickFP(props.row)}>{props.row.xspjfp}</a>;
          }
        },
        {
          title: '来款备注',
          dataIndex: 'xtlkbz',
          sorter: true,
          render: props => {
            return props.row.xssffl=='1'?'返利': props.row.xtlkbz
          }
        }
      ]
    },
    clickFP(row){
      this.issearchKP = true
      this.formData = row
    },
    KPcloseHandler(){
      this.issearchKP = false;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    seacherFun(){
      this.issearch = true
    },
    // 选择经销商回调
    dealercloseHandler(val){
      if(val){
        this.topFilterList.find(x=>x.fieldName=='xskhdm').initialValue=val.dealerCode;
      }
      this.issearch = false;
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
  }
}
</script>

<style scoped>

</style>
